(function ($) {
  /* ------------------------------- */
  $(function(){
    load_event();
	login_event();
	friendImg_event();
	message_event();
	bigsbox();
	acivity_event();
	footerpanel_event();
	useroption_event();
	shareconnect_event();
	googlemap_event();
	//$(".bigsbox").fancybox();
	bigs_model_event();
	bigsscrollpane();
    /*slidescroll*/
/**/
$("#topics dt:even").addClass("bg_b");
  });

})(jQuery);

/*image rollover*/
var load_event = function(){
  $('a>img[src*="-out-"],input[src*="-out-"]').each(function(){
    var $$ = $(this);
    $$.mouseover(function(){ $(this).attr('src', $(this).attr('src').replace(/-out-/,'-on-')) });
    $$.mouseout (function(){ $(this).attr('src', $(this).attr('src').replace(/-on-/,'-out-')) });
  });
}

var login_event = function(){
  $('#loginpanel').each(function(){
    var $$ = $(this);
    $$.mouseover(function(){ $('.loginbutton:first').addClass("active");});
    $$.mouseout (function(){ $('.loginbutton:first').removeClass("active");  });
  });
}

var friendImg_event = function(){
  $('.afriend').each(function(){
    var $$ = $(this);
    var $id=$$.attr('id');
    $$.mouseover(function(){ $("#info"+$id).show(); });
    $$.mouseout (function(){  $("#info"+$id).hide();  });
  });
}
var bigsscrollpane=function(){
  $('#popup').each(function(){
    if($('#popup').height()>=400){
  		  $('#popupcontent').jScrollPane();
    }
    $(".bigsbox").fancybox({
    	
    });
    
  });
}
var bigs_model_event=function(){
  $('.bigs_model_content').each(function(){
    if($('.bigs_model_content').height()>=240){
  		  $('.bigs_model_content').jScrollPane();
    }
    $(".bigsbox").fancybox({
    	
    });
    
  });
}
var bigsbox=function(){
  $('.bigsbox').each(function(){
    $(this).click(function(){  
    	$(".bigsbox").fancybox({
    		maxWidth	: 800,
    		width		: '100%'
    	});});
  });
}
var message_event=function(){
  $('.messager_detail_box').each(function(){
    $(this).mouseover(function(){  
    	$.get('http://localhost/popup/message/'+$(this).attr('href'), function(data) { $('.jspPane').html(data);});
    	console.log('http://localhost/popup/message/'+$(this).attr('href'));
    	$('.jspContainer').height($('.jspPane').height());
    	$('.jspTrack').height($('.jspPane').height());
  });
})}
var acivity_event=function(){
  $('#activity_header a').each(function(){
  	$(this).unbind('click').bind('click',function () { 
  		$('#user_status').fadeTo("slow", 0, function () {
				$('#user_status').removeClass('Big_status_show').css({'z-index':0});
			  }); 	
  		if($('#activity_view').width()==32){
  			$('#activity_view').width(314); 
  			$('#activity_panel').animate({"right" : "281px"}, 1500);
  		}else{
  			$('#activity_panel').animate({"right" : "0px" }, 1500,function () {
				$('#activity_view').width(32);
			  }); 			
  		}
  		 });
	})  
}
var footerpanel_event=function(){
  $('.bigs_model_header').each(function(){
  	
   	var id=$(this).parent().parent();
  	console.log(id);
  	$(this).click(function () {
  		var id='#'+$(this).parent().parent().attr('id');
		console.log(id);
		console.log($(id+'.bigs_model_panel').height());
		if($(id+'.bigs_model_panel').height()==35){
			$(id+'.bigs_model_panel').height(315);
			$(id+' div.bigs_model_view').animate({"bottom" : "35px"}, 1500,function () {
			  $(id+' div.bigs_model_footer').fadeTo("slow", 1.0).css({'z-index':2});
			});
			console.log($(id+'.bigs_model_panel').height());
		}else{
			$(id+' div.bigs_model_footer').fadeTo("slow", 0,function () {
				$(id+' div.bigs_model_view').animate({"bottom" : "-240px"}, 1500, function () {
			  $(id+'.bigs_model_panel').height(35);
			});
			  }).css({'z-index':0});
		}
	  })
})
}

var useroption_event=function(){
	$('#option_button').each(function () {
	  $(this).unbind('click').bind('click',function () {
	  	console.log($('#user_status').attr('class'));
	  	if($('#activity_view').width()==314){
  			$('#activity_panel').animate({"right" : "0px" }, 1500,function () {
				$('#activity_view').width(32);
				$('#user_status').fadeTo("slow", 1.0, function () {					
					$('#user_status').addClass('Big_status_show');
				  }).css({'z-index':2});
			  }); 
  		}else if($('#user_status').attr('class')=='Big_status_show'){
  			$('#user_status').fadeTo("slow", 0, function () {
				$('#user_status').removeClass('Big_status_show').css({'z-index':0});;
			  });
  		}else{
  			$('#user_status').fadeTo("slow", 1.0, function () {
				$('#user_status').addClass('Big_status_show');
			  }).css({'z-index':2});
  		}
		
	  });
	  $('#user_status').unbind('click').bind('click',function () {
		$('#user_status').fadeTo("slow", 0, function () {
				$('#user_status').removeClass('Big_status_show').css({'z-index':0});;
			  });
	  })
	})
}
var shareconnect_event=function(){
	$('#share_connect .share_connect_header').each(function(){
		$(this).unbind('click').bind('click',function  () {
			if($('.share_connect_content').width()==0){
				$('.share_connect_content').fadeTo("fast", 1.0,function  () {
				   $('.share_connect_content ul').animate({"left" : "160px" }, 1500,function  () {
					 
				   });
				}).width(160);
			}else{
				$('.share_connect_content ul').animate({"left" : "0px" }, 1500,function  () {
				  $('.share_connect_content').fadeTo("fast", 0,function () {
					 $('.share_connect_content').width(0);
				  })
				});
				
			}
		 
		})
	})
}
var googlemap_event=function(){
	var map;
	var markersArray = [];
	 
	$('body').each(function(){
		var styles = [{stylers: [{ hue:'blue'},{ saturation: -20 }]},
					  {featureType: "road",elementType: "geometry",stylers: [{ lightness: 100 },{ visibility: "simplified" }]},
					  {featureType: "road",elementType: "labels",stylers: [{ visibility: "off" }]}]; 
		var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"}); 
		$('#map_canvas').height($('body').height()-70);
		var mapOptions = {
		    zoom: 5,
		    center: new google.maps.LatLng(14.0583240,108.2771990),
		    mapTypeId: google.maps.MapTypeId.ROADMAP
		}
	 
		map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
		map.setOptions({styles: styles});
	  
		var myLatLng = new google.maps.LatLng(10.86399,106.809425);
		var my_maker = new google.maps.Marker({position: myLatLng,map: map,title:"Đại Học Quốc Gia Tp.HCM"});
		
		var point = new google.maps.LatLng(10.948608,106.669693);
		var marker = new google.maps.Marker({ position: point, title:"Q.9"});
		marker.setMap(map);
					
		//google.maps.event.addListener(map, 'click', function(event) {addMarker(event.latLng);}); 
		ajax_loadxml();	
  	});


	
	function addMarker(location) {
		marker = new google.maps.Marker({
		    position: location,
		    map: map
	  	});
		markersArray.push(marker);
	}
	
	function ajax_loadxml(){
	$.ajax({
				type: "GET",
				url: "xml/point.xml",
				dataType: "xml",
				success: function(xml) {
					$(xml).find('marker').each(function(){
						var title = $(this).attr('title');
						var lat = $(this).find('lat').text();
						var lng = $(this).find('lng').text();
						var point = new google.maps.LatLng(lat,lng);
						var marker = new google.maps.Marker({ position: point, title:title});
						marker.setMap(map);
						
					});
				}
			});
	}
	
}
